package com.lottoad.android.cronos.parser;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.lottoad.android.cronos.data.CNLottoAdMyPageData;
import com.lottoad.android.cronos.datahandler.CNBaseDataParser;
import com.lottoad.android.cronos.datahandler.CNResultSet;

public class CNLottoMypageParser extends CNBaseDataParser{
	protected void onParseContent(Element xmlObject, CNResultSet resultSet)
			throws Exception {
		
		NodeList nodeList = xmlObject.getElementsByTagName("winner");
		
		NodeList nodeNujukMoney = xmlObject.getElementsByTagName("totalNujukMoney");
		NodeList nodeAskMoney = xmlObject.getElementsByTagName("totalAskMoney");
		NodeList nodePaidMoney = xmlObject.getElementsByTagName("totalPaidMoney");
		NodeList nodeUsableMoney = xmlObject.getElementsByTagName("totalUsableMoney");
		
		resultSet.setNujukMoney(nodeNujukMoney.item(0).getFirstChild().getNodeValue());
		resultSet.setAskMoney(nodeAskMoney.item(0).getFirstChild().getNodeValue());
		resultSet.setPaidMoney(nodePaidMoney.item(0).getFirstChild().getNodeValue());
		resultSet.setUsableMoney(nodeUsableMoney.item(0).getFirstChild().getNodeValue());
		
		NodeList nodeChaSeq = xmlObject.getElementsByTagName("chaSeq");
		NodeList nodeDate = xmlObject.getElementsByTagName("receiveDate");
		NodeList nodeLottoNum = xmlObject.getElementsByTagName("lottoNum");
		NodeList nodeRealMoney = xmlObject.getElementsByTagName("realMoney");
		NodeList nodeRank = xmlObject.getElementsByTagName("rank");
				
		NodeList totalCntNode = xmlObject.getElementsByTagName("totalCount");
		String totalCnt = totalCntNode.item(0).getFirstChild().getNodeValue();
		resultSet.setTotalCount(Integer.parseInt(totalCnt));
		
		int count = nodeList.getLength();
		
		for (int i = 0; i < count; i++)
		{
			Element elementData = (Element) nodeList.item(i);
			if (elementData == null)
				continue;
			
			CNLottoAdMyPageData dataSet = new CNLottoAdMyPageData();
			
			if(nodeChaSeq.item(i).getFirstChild() != null)
				dataSet.chaSeq = Integer.parseInt(nodeChaSeq.item(i).getFirstChild().getNodeValue());
			
			if(nodeDate.item(i).getFirstChild() != null)
				dataSet.recDate = nodeDate.item(i).getFirstChild().getNodeValue();
			
			if(nodeLottoNum.item(i).getFirstChild() != null)
				dataSet.lottoNum = nodeLottoNum.item(i).getFirstChild().getNodeValue();
			
			if(nodeRealMoney.item(i).getFirstChild() != null)
				dataSet.realMoney = nodeRealMoney.item(i).getFirstChild().getNodeValue();
			
			if(nodeRank.item(i).getFirstChild() != null)
				dataSet.rank = nodeRank.item(i).getFirstChild().getNodeValue();
			
			resultSet.addDataSet(dataSet);
		}
	}
}
